Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Previewnet temporary fix for missing timestamps #245

Merged
merged 1 commit into from
May 14, 2024
Merged

Conversation

devbugging
Copy link
Contributor

@devbugging devbugging commented May 14, 2024

This PR is a TEMPORARY FIX on previewnet for missing timestamps.

Summary by CodeRabbit

  • Bug Fixes
    • Implemented a temporary fix to ensure accurate timestamps in blockchain data, resolving issues where timestamps were previously set to zero.

Copy link
Contributor

coderabbitai bot commented May 14, 2024

Walkthrough

A temporary fix was implemented in the BlockChainAPI class within api/api.go to handle cases where block.Timestamp is 0. The solution involves calculating a new timestamp based on specific conditions to ensure the system can continue functioning smoothly without encountering errors due to missing timestamps.

Changes

File Change Summary
api/api.go Added logic to the prepareBlockResponse function to mock timestamps if block.Timestamp is 0

🌸 In code, a fix, a timestamp tweak,
To make our blockchain strong, not weak.
When time stands still, we craft anew,
A mock, a patch, for blocks to queue.
🐇 With every change, progress we seek.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@devbugging devbugging requested a review from ramtinms May 14, 2024 17:20
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 4cd2076 and 5e60f77.
Files selected for processing (1)
  • api/api.go (1 hunks)

Comment on lines +616 to +626
// todo remove after previewnet, temp fix to mock some of the timestamps
if block.Timestamp == 0 {
first := uint64(1715189257)
blockTime := uint64(200)
firstRecordedTimestampBlock := uint64(5493)

diff := firstRecordedTimestampBlock - block.Height
timestamp := first - blockTime*diff

blockResponse.Timestamp = hexutil.Uint64(timestamp)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure the temporary fix is clearly marked and documented.

The temporary fix for missing timestamps is clearly marked with a TODO comment. However, it would be beneficial to add more context about why this fix is necessary and any potential impacts. This will help future maintainers understand the reason behind this code and when it can be safely removed.

Consider adding a more detailed comment like this:

// TODO: Remove after previewnet, temp fix to mock some of the timestamps
// This temporary fix addresses the issue of missing timestamps in previewnet.
// It calculates a mock timestamp based on a predefined starting point and block time.
// This fix should be removed once the underlying issue is resolved.

blockTime := uint64(200)
firstRecordedTimestampBlock := uint64(5493)

diff := firstRecordedTimestampBlock - block.Height
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just check diff doesn't get negative

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did in a local test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add an if statement tho, but then what value to assign :D

firstRecordedTimestampBlock := uint64(5493)

diff := firstRecordedTimestampBlock - block.Height
timestamp := first - blockTime*diff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be + ? I also think you might multiply it by second.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be - because what I did is checked what is the first timestamp we have indexed, which is: 1715189257 then I subtract 200 (average block timestamp change I calculated) as many times as there is a diff from the height of the block that has this value and the block we are generating. Basically height 0 would have biggest change and height 5492 which is one less than first recorded timestamp would have lowest change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could have better documented, but this will all go away

Copy link
Contributor

@ramtinms ramtinms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left some suggestions.

@devbugging devbugging merged commit 77e4f79 into main May 14, 2024
2 checks passed
@m-Peter m-Peter deleted the timestamp-temp-fix branch July 29, 2024 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants